/*1*/ package Vista;
/*2*/
/*3*/ import Controlador.ControladorObtenerActores;
/*4*/ import java.awt.Color;
/*5*/ import java.awt.Point;
/*6*/ import java.awt.event.MouseEvent;
/*7*/ import java.awt.event.MouseMotionAdapter;
/*8*/ import java.awt.event.WindowAdapter;
/*9*/ import java.awt.event.WindowEvent;
/*10*/ import java.io.File;
/*11*/ import java.util.Vector;
/*12*/ import javax.swing.JOptionPane;
import javax.swing.table.TableColumn;
/*13*/
/*14*/ /**
        * Clase VistaObtenerActores genera la vista de obtencion de actores
        * a partir de clientes y realizadores (quinta vista).
        */
public class JPObtenerActores extends javax.swing.JPanel {

    /*20*/     ControladorObtenerActores control;
    /** Creates new form JPObtenerActores */
    public JPObtenerActores(ControladorObtenerActores controlador) {
/*27*/         this.control = controlador;
/*28*/         //seteo de datos en la tabla
/*29*/         initComponents();
/*30*/         this.setNomCU();
/*31*/         if (this.control.revisionAgentes() == 1) {
/*32*/             this.setClientes();
/*33*/             this.setRealizadores();
/*34*/         }
/*35*/         this.tActores.setEnabled(false);
/*36*/
/*37*/         //para visualizar el contenido de una celda al pasar el mouse por ella
/*38*/         this.tActores.addMouseMotionListener(new MouseMotionAdapter() {
/*39*/
/*40*/             @Override
/*41*/             public void mouseMoved(MouseEvent e) {
/*42*/                 Point p = e.getPoint();
/*43*/                 int row = tActores.rowAtPoint(p);
/*44*/                 int column = tActores.columnAtPoint(p);
/*45*/                 tActores.setToolTipText(String.valueOf(tActores.getValueAt(row, column)));
/*46*/             }
/*47*/         });
/*48*/         //En caso de cerrar la ventana se pedirá guardar la información
///////*49*/         this.addWindowListener(new WindowAdapter() {
///////*50*/
///////*51*/             @Override
///////*52*/             public void windowClosing(WindowEvent e) {
///////*53*/                 javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
///////*54*/                 String ruta = "";
///////*55*/                 try {
///////*56*/                     if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
///////*57*/                         ruta = jF1.getSelectedFile().getAbsolutePath();
///////*58*/                         if (new File(ruta).exists()) {
///////*59*/                             if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(null, "El fichero existe,desea reemplazarlo?", "Titulo", JOptionPane.YES_NO_OPTION)) {
///////*60*/                                 control.archivoSesion(ruta);
///////*61*/                             }
///////*62*/                         } else {
///////*63*/                             control.archivoSesion(ruta);
///////*64*/                         }
///////*65*/                     }
///////*66*/                 } catch (Exception ex) {
///////*67*/                     ex.printStackTrace();
///////*68*/                 }
///////*69*/
///////*70*/                 System.exit(0);
///////*71*/             }
///////*72*/         });
/*73*/
/*74*/     }
/*75*/
/*76*/     //seteo del nombre de los casos de uso en la tabla
/*77*/         /**
     * Seteo del nombre de los casos de uso en la tabla
     */
/*80*/     public void setNomCU() {
/*81*/         Vector nomCU = new Vector();
/*82*/         nomCU = this.control.getNombreCasoUso();
/*83*/         this.setFilas(nomCU.size());
/*84*/         for (int i = 0; i < nomCU.size(); i++) {
/*85*/             this.tActores.setValueAt(nomCU.get(i), i, 1);
                    Integer intObj = new Integer(i+1);   //agrega el numero a la fila
                          this.tActores.setValueAt(intObj, i, 0);
/*86*/         }
/*87*/     }
/*88*/
/*89*/     //seteo de los clientes en la tabla
/*90*/         /**
     * Seteo de los clientes en la tabla
     */
/*93*/     public void setClientes() {
/*94*/         Vector clientes = new Vector();
/*95*/         clientes = (Vector) this.control.getClientes();
/*96*/         for (int i = 0; i < clientes.size(); i++) {
/*97*/             this.tActores.setValueAt(clientes.get(i), i, 2);
/*98*/         }
/*99*/     }
/*100*/
/*101*/     //seteo de los realizadores en la tabla
/*102*/         /**
     * Seteo de los realizadores en la tabla
     */
/*105*/     public void setRealizadores() {
/*106*/         Vector realizadores = new Vector();
/*107*/         realizadores = (Vector) this.control.getRealizadores();
/*108*/         for (int j = 0; j < realizadores.size(); j++) {
/*109*/             this.tActores.setValueAt(realizadores.get(j), j, 3);
/*110*/         }
/*111*/     }
/*112*/
/*113*/     //seteo de las propiedades de la tabla
/*114*/         /**
     * Seteo de las propiedades de la tabla
     * @param tam Tamaño de las filas utilizadas
     */
/*118*/     public void setFilas(int tam) {
/*119*/         javax.swing.table.DefaultTableModel tabla = new javax.swing.table.DefaultTableModel(
/*120*/                 new Object[][]{
/*121*/                     {null, null, null}
/*122*/                 },
/*123*/                 new String[]{
/*124*/                     "Número","Caso de Uso", "Cliente", "Realizador"
/*125*/                 });
/*126*/         tabla.setRowCount(tam);
/*127*/         tabla.setColumnCount(4);
/*128*/         this.tActores.setModel(tabla);
/*129*/         this.tActores.getColumnModel().getColumn(2).setCellRenderer(new TextAreaRenderer());
/*130*/         this.tActores.getColumnModel().getColumn(3).setCellRenderer(new TextAreaRenderer());
/*131*/         this.tActores.setShowGrid(true);
/*132*/         this.tActores.setGridColor(Color.black);
                TableColumn col= tActores.getColumn("Número");
                col.setMaxWidth(50);
/*133*/     }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tActores = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(proyectodetitulo.ProyectoDeTituloApp.class).getContext().getResourceMap(JPObtenerActores.class);
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tActores.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Caso de Uso", "Cliente", "Realizador"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tActores.setName("tActores"); // NOI18N
        jScrollPane1.setViewportView(tActores);

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 926, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addGap(62, 62, 62)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(170, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tActores;
    // End of variables declaration//GEN-END:variables

}
